package uk.ac.nott.cs.g53dia;

import utils.Constants;

/**
 * Action which moves the bee one cell in a specified direction.
 *
 * @author Neil Madden.
 */
/*
 * Copyright (c) 2005 Neil Madden (nem@cs.nott.ac.uk)
 * 
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */
public class MoveAction implements Action {
    /**
     * Direction to move in.
     */
    private int direction;
    public final static int
        NORTH       =   0,
        SOUTH       =   1,
        EAST        =   2,
        WEST        =   3,
        NORTHEAST   =   4,
        NORTHWEST   =   5,
        SOUTHEAST   =   6,
        SOUTHWEST   =   7;

    public MoveAction(int dir) {
        direction = dir;
    }

    public void execute(Environment env, Bee bee)
        throws ActionFailedException
    {
        switch (direction) {
            case NORTH:
                bee.position.y++;
                break;
            case SOUTH:
                bee.position.y--;
                break;
            case EAST:
                bee.position.x++;
                break;
            case WEST:
                bee.position.x--;
                break;
            case NORTHEAST:
                bee.position.x++; bee.position.y++;
                break;
            case NORTHWEST:
                bee.position.x--; bee.position.y++;
                break;
            case SOUTHEAST:
                bee.position.x++; bee.position.y--;
                break;
            case SOUTHWEST:
                bee.position.x--; bee.position.y--;
                break;
            default:
                throw new ActionFailedException("Move: not a direction: "
                        + direction);
        }
        Environment.moveBee(bee);
        bee.useEnergy(1);
    }

    private static final String DIRECTION[] = {
        "NORTH", "SOUTH", "EAST", "WEST", "NORTHEAST",
        "NORTHWEST", "SOUTHEAST", "SOUTHWEST"
    };
    public String toString() {
        return "Move " + DIRECTION[direction];
    }

	public String getCode() {
		return Constants.MOVE_ACTION_CODE + Constants.ACTION_ARGS_SEPARATOR + direction;
	}


}
